<?
session_start();
if (!isset($_SESSION[login])) {
     header("Location: HomeIndex.php");
     exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Search Teacher</title>
<meta charset="utf-8">
<meta name="description" content="Place your description here">
<meta name="keywords" content="put, your, keyword, here">
<meta name="author" content="Templates.com - website templates provider">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<!--[if lt IE 7]>
     <link rel="stylesheet" href="css/ie/ie6.css" type="text/css" media="screen">
     <script type="text/javascript" src="js/ie_png.js"></script>
     <script type="text/javascript">
        ie_png.fix('.png, footer, header nav ul li a, .nav-bg, .list li img');
     </script>
<![endif]-->
<!--[if lt IE 9]>
  	<script type="text/javascript" src="js/html5.js"></script>
  <![endif]-->
</head>
<body id="page2" onLoad="MM_preloadImages('images/btn_download/btn_download_2.gif')">
<div class="wrap">
   <!-- header -->
   <header>
      <div class="container">
         <h1><a href="homeTeacher.php">Student Portfolio Management System</a></h1>
         <nav>
            <ul>
               <li><a href="homeTeacher.php" class="m1">หน้าแรก</a></li>
               <li class="current"><a href="searchTeacher.php" class="m1">ค้นหา</a></li>
               <li class="last"><a href="reportTeacher.php" class="m3">ออกรายงาน</a></li>
            </ul>
         </nav>
         <form action="" id="search-form">
            <fieldset>
            <div class="rowElem">
               <input type="text">
               <a href="#" onClick="document.getElementById('search-form').submit()">ค้นหา</a></div>
            </fieldset>
         </form>
      </div>
   </header>
   <div class="container">
      <!-- aside -->
      <aside>
         <div class="wrap">
   <!-- header -->
   <div class="container">
      <!-- aside -->
      <aside><h2 align ="left">ยินดีต้อนรับ</h2> 
	  <p><? echo $_SESSION["ses_name"]; ?></p>
      <input name="editselfTeacher" type="button" value="แก้ไขข้อมูลส่วนตัว" onClick="editselfTeacher.php"><br><br>
      <input name="logOut" type="button" value="ออกจากระบบ" onClick="window.location='logout.php'">
</aside>	 
      <!-- content -->
      <section id="content">   
         <div class="inside">
           <table width="650" height="187" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="39" colspan="4"><div align="center">
        <p align="left" class="style30">ระบบการค้นหาข้อมูล</p>
        <hr/>
        <br>
      </div></td>
    </tr>
    <tr bordercolor="#999999">
      <td width="122" height="37"><div align="right"></div></td>
      <td width="105" height="37" valign="middle"><div align="left">ค้นหา
      </div></td>
      <td width="200" valign="middle">
      <form name="searchpro" method="post" action="searchAdmin.php"> 
         <div align="left">
           <input type="text" size="30" name="text" />
      </div></td>
      <td width="223" valign="middle">&nbsp;&nbsp;<select name="selectpro">
        <option>ชื่อเจ้าของผลงาน</option>
        <option>รหัสนักศึกษา</option>
        <option>ชื่อสาขา</option>
        <option>ชื่อรายวิชา</option>
        <option>ชื่อผลงาน</option>
      </select></td>
    </tr>
    <tr bordercolor="#999999">
      <td height="37">&nbsp;</td>
      <td height="37" valign="middle"><div align="left">ประเภทผลงาน</div></td>
      <td height="37" valign="middle"> <select name="type">
	  <option>เลือกประเภทผลงาน</option>
	  <? require("connectDB.php");
	$query_list=mysql_query("Select * From project_type");
	while($arrL= mysql_fetch_array($query_list))
	{
	?>
	<option><? echo $arrL['project_type'];?></option>
	<?
	}
	mysql_free_result($query_list);
	?>
	</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#999999">
      <td height="37">&nbsp;</td>
      <td height="37" valign="middle"><div align="left">ปีการศึกษา</div></td>
      <td height="37" valign="middle"><select name="year">
	  <option>เลือกปีการศึกษา</option>
	  <? require("connectDB.php");
	$query_list=mysql_query("Select * From year");
	while($arrL= mysql_fetch_array($query_list))
	{
	?>
	<option><? echo $arrL['year'];?></option>
	<?
	}
	mysql_free_result($query_list);
	?>
	</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr bordercolor="#999999">
      <td height="37" colspan="4"><div align="center">
        <input type="submit" name="Submit" value="ค้นหา" />
      </div></td>
    </tr>
    </form>
  </table>
  <br>
  <table width="650" height="40" border="1" cellpadding="0" cellspacing="0" bordercolor="#666666">
    <tr>
      <td width="80" height="30" valign="middle" bgcolor="#DFE6EF"><div align="center" class="style29">สาขา</div></td>
      <td width="240" bordercolor="#666666" valign="middle" bgcolor="#DFE6EF"><div align="center" class="style29">ชื่อรายวิชา</div></td>
      <td width="143" bordercolor="#666666" valign="middle" bgcolor="#DFE6EF"><div align="center" class="style29">ชื่อผู้ใช้</div></td>
      <td width="234" bordercolor="#666666" valign="middle" bgcolor="#DFE6EF"><div align="center" class="style29">ชื่อผลงาน</div></td>
      <td width="130" bordercolor="#666666" valign="middle" bgcolor="#DFE6EF"><div align="center" class="style29">สถานะผลงาน</div></td>
      <td width="149" bordercolor="#666666" valign="middle" bgcolor="#DFE6EF"><div align="center"><span class="style29">ดาวน์โหลดDemo</span></div></td>
    </tr>
<? require("connectDB.php");    //include "connectdb.inc";
if ($type == "เลือกประเภทผลงาน"){
if ($selectpro == "ชื่อผลงาน")
$tmp="select * from project where project_name like '$text%' order by project_id;";
else if ($selectpro == "ชื่อเจ้าของผลงาน")
$tmp="select * from project where owner_name like '$text%' order by project_id;";
else if ($selectpro == "ชื่อรายวิชา")
$tmp="select * from project where subject like '$text%' order by project_id;";
else if ($selectpro == "ชื่อสาขา")
$tmp="select * from project where major like '$text%' order by project_id;";
else if ($selectpro == "รหัสนักศึกษา")
$tmp="select * from project where student_id like '$text%' order by project_id;";
else if ($text == "")
$tmp="select * from project order by project_id;";
}
else if ($selectpro == "ชื่อเจ้าของผลงาน")
$tmp="select * from project where owner_name like '$text%' and project_type like '$type' order by project_id;";
else if ($selectpro == "รหัสนักศึกษา")
$tmp="select * from project where student_id like '$text%' and project_type like '$type' order by project_id;";
elseif ($selectpro == "ชื่อสาขา")
$tmp="select * from project where major like '$text%' and project_type like '$type' order by project_id;";
else if ($selectpro == "ชื่อรายวิชา")
$tmp="select * from project where subject like '$text%' and project_type like '$type' order by project_id;";
else if ($selectpro == "ชื่อผลงาน")
$tmp="select * from project where project_name like '$text%' and project_type like '$type' order by project_id;";
else
$tmp="select * from project order by project_id;";

//echo($tmp);
$sql = mysql_query($tmp);
while($result = mysql_fetch_array($sql))    { ?>
<TR>
<TD align="center"><? echo $result["major"]; ?></TD>
<td><? echo $result["subject"]; ?></td>
<td><? echo $result["owner_name"]; ?></td>
<TD><a href="viewAdmin.php?pid=<? echo $result["project_id"]; ?>" > <? echo $result["project_name"]; ?></TD>
<TD align="center"><? echo $result["project_status"]; ?></td>
<?if($result["project_status"]=="ไม่อนุญาต"){?>
<TD align="center"><a onclick="error()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Download','','images/btn_download/btn_download_2.gif',1)"><img src="images/btn_download/btn_download_1.gif" alt="ดาวน์โหลดผลงาน" width="100" height="30" id="Download"></a></td> <? }
else {?>
<TD align="center"><a href="TheFile/Demo/<?=$result["demo_file"];?>" target="_blank" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Download','','images/btn_download/btn_download_2.gif',1)"><img src="images/btn_download/btn_download_1.gif" alt="ดาวน์โหลดผลงาน" width="100" height="30" id="Download"></a></td><?}?>
</tr>
<? }
mysql_free_result($sql);
mysql_close($con); ?>               
  </table>  
         </div>
      </section>  
   </body>
</html>
